# 各种工具类 或者变量
import datetime
import hashlib
import os
import re

from src import evaluate

LACK_OF_PARAMS = 'lack of params : [%s]'  # 缺少变量

# 国际象棋的棋盘大小 只能是8
BOARD_SIZE = 8

ALPHABET = {
    'a': 1,
    'b': 2,
    'c': 3,
    'd': 4,
    'e': 5,
    'f': 6,
    'g': 7,
    'h': 8,
    1: 1,
    2: 2,
    3: 3,
    4: 4,
    5: 5,
    6: 6,
    7: 7,
    8: 8,
    '1': 1,
    '2': 2,
    '3': 3,
    '4': 4,
    '5': 5,
    '6': 6,
    '7': 7,
    '8': 8,
}


# 获取形如 20210929170621 的时间字符串
def getCurrentTimeStr() -> str:
    time_stamp = datetime.datetime.now()
    return time_stamp.strftime('%Y%m%d%H%M%S')


# 获取形如 2021-09-29 17:06:21 的时间字符串
def getCurrentTimeFormat() -> str:
    time_stamp = datetime.datetime.now()
    return time_stamp.strftime('%Y-%m-%d %H:%M:%S')


# 获取形如 2021-10-5 的时间字符串
def getCurrentDateStr() -> str:
    time_stamp = datetime.datetime.now()
    return time_stamp.strftime('%Y-%m-%d')


# 获取一个字符串的md5
def getMd5(data) -> str:
    return hashlib.md5(data.encode(encoding='UTF-8')).hexdigest()


# 获取配置文件的键值
def get_config_by_key(config, key: str):
    if key in config:
        return config[key]
    else:
        return None


# 获取数组的最后一项
def get_list_last_item(data: list):
    return data[len(data) - 1]


# 判断x y坐标是否在对象中
def check_if_in_dict(data: dict, x, y) -> bool:
    if x in data:
        temp = data[x]
        if y in temp:
            return True
        else:
            return False
    else:
        return False


# 按照键值给数组字典排序
def sort_list_by_key(sort_list, key, desc: bool or evaluate.Color) -> list:
    return sorted(sort_list, reverse=desc, key=lambda e: e.__getitem__(key))
